//
//  ZNewPartOnAlertView.m
//  DistributorAB
//
//  Created by LZY on 2019/10/17.
//  Copyright © 2019 主事丫环. All rights reserved.
//

#import "ZNewPartOnAlertView.h"
#import "BBuyNowRecommendVC.h"

@interface ZNewPartOnAlertView ()
@property (nonatomic, strong) UILabel *lblContent;//提示文案
@end

@implementation ZNewPartOnAlertView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupViewAction];
    }
    return self;
}
#pragma mark - 界面布局
- (void)setupViewAction{
    self.backgroundColor = kColorWithHex(0xb1b0af);
    
    UIImageView *ivBg = [UIImageView new];
    ivBg.image = imgname(@"push_new_part_on_alert_icon");
    [self addSubview:ivBg];
    [ivBg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self);
        make.size.mas_equalTo(CGSizeMake(kScaleNum(322), kScaleNum(283)));
    }];
    
    
    UIButton *btnBuy = [UIButton buttonWithType:UIButtonTypeCustom];
    [btnBuy setImage:imgname(@"btn_buy_now_icon") forState:UIControlStateNormal];
    [self addSubview:btnBuy];
    [btnBuy addTarget:self action:@selector(btnBuyClickAction:) forControlEvents:UIControlEventTouchUpInside];
    [btnBuy mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.mas_centerX);
        make.bottom.equalTo(ivBg.mas_bottom).offset(-kScaleNum(35));
        make.size.mas_equalTo(CGSizeMake(kScaleNum(182), kScaleNum(43)));
    }];
    
    _lblContent = [UILabel new];
    _lblContent.font = [UIFont boldSystemFontOfSize:20];
    _lblContent.textColor = kColorWithHex(0x333333);
    _lblContent.textAlignment = NSTextAlignmentCenter;
    _lblContent.numberOfLines = 2;
    [self addSubview:_lblContent];
    [_lblContent mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.bottom.equalTo(btnBuy.mas_top).offset(-17);
    }];
    
    UIButton *btnClose = [UIButton buttonWithType:UIButtonTypeCustom];
    [btnClose setTitle:@"关闭" forState:UIControlStateNormal];
    [btnClose setTitleColor:kColorWithHex(0xffffff) forState:UIControlStateNormal];
    btnClose.titleLabel.font = [UIFont systemFontOfSize:14];
    [btnClose addTarget:self action:@selector(btnCloseClickAction:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:btnClose];
    [btnClose mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(ivBg.mas_top);
        make.trailing.equalTo(ivBg.mas_trailing);
    }];
}
- (void)setAlertType:(NSString *)alertType{
    _alertType = alertType;
    if ([alertType isEqualToString:@"1"]) {
        _lblContent.text = @"新配件已上架\n请到配件商城中查看";
    }else if ([alertType isEqualToString:@"2"]){
        _lblContent.text = @"新整机已上架\n请到整机商城中查看";
    }
}
#pragma mark - 交互方法
//显示
- (void)showView{
    UIWindow *window = [[[UIApplication sharedApplication] delegate] window];
    self.frame = window.bounds;
    [window addSubview:self];
}
//关闭
- (void)dismissView{
    [self removeFromSuperview];
    
}
- (void)btnBuyClickAction:(UIButton *)sender{
    
    if (self.delegate && [self.delegate respondsToSelector:@selector(viewBtnBuyNowClick:)]) {
        [self.delegate viewBtnBuyNowClick:self.alertType];
    }else{
        BBuyNowRecommendVC *vc = [BBuyNowRecommendVC new];
        if ([self.alertType isEqualToString:@"1"]) {
            vc.type = RecommendVCTypeNew;//配件
        }else if ([self.alertType isEqualToString:@"2"]){
            vc.type = RecommendVCTypeBest;//整机
        }
        [[HFTools getCurrentVC].navigationController pushViewController:vc animated:YES];
    }
    
    [self dismissView];
}
- (void)btnCloseClickAction:(UIButton *)sender{
    [self dismissView];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
